package pe.tnova.adra.kernel.log;
import org.apache.log4j.LogManager;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.ConsoleAppender;
import ch.qos.logback.core.FileAppender;

public class PatternSample {
	//http://www.ivoronline.com/Coding/Languages/JAVA/APIS/JAVA%20-%20Log4j%20-%20XML%20-%20Layouts%20-%20HTMLLayout.php
//http://howtodoinjava.com/2013/04/08/how-to-create-logs-in-html-format-using-log4j/
  static public void main(String[] args) throws Exception {
    Logger rootLogger = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    LoggerContext loggerContext = rootLogger.getLoggerContext();
    loggerContext.reset();
    LogManager.resetConfiguration();
    loggerContext.resetTurboFilterList();
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(loggerContext);
    encoder.setPattern("%-5level [%thread]: %message%n");
    encoder.start();
    ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
    appender.setContext(loggerContext);
    appender.setEncoder(encoder); 
    appender.start();    
    rootLogger.addAppender(appender);
    rootLogger.setLevel(Level.INFO );//cambio de nivel
    System.out.println(rootLogger.isInfoEnabled());
    System.out.println(rootLogger.isDebugEnabled());
    System.out.println(rootLogger.isErrorEnabled());
    System.out.println(rootLogger.isTraceEnabled());
    System.out.println(rootLogger.isWarnEnabled());    
    rootLogger.debug("Message 1"); 
    rootLogger.info("Message info");
    rootLogger.warn("Message 2");
    rootLogger.error("error");
    rootLogger.trace("msg trace");
    FileAppender<ILoggingEvent> appenderFile =  new FileAppender<ILoggingEvent>();
    appender.setContext(loggerContext);
    appender.setEncoder(encoder); 
    appender.start();    
    rootLogger.addAppender(appender);
    
    
    
    
    
    
  } 
}